package com.cip.master.action;

import java.util.ArrayList;
import java.util.List;


import com.cip.admin.model.User;
import com.cip.common.util.CommonUtil;
import com.cip.common.util.SecurityUtil;
import com.cip.master.model.Section;
import com.cip.master.service.SectionService;
import com.cip.webapp.action.BaseAction;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class CommonAction extends  BaseAction{
	public String className;
	private SectionService sectionService;
	
	
	
	public void getSectionByClassName() throws Exception{
		/*JSONObject jsonobject = new JSONObject();
		User user = SecurityUtil.getThreadLocalUser().get();
		List<Section> sectionList = sectionService.getAllSectionByClassYear(Integer.valueOf(""));
		System.out.println("sectiolIst============"+sectionList.size());
		
		try{
			
			jsonobject.put("username", user.getUsername());
			jsonobject.put("userName", userList);
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			CommonUtil.generateResponseThroughJSON(getResponse(), jsonobject);
		}
	*/	
	}


	public String getClassName() {
		return className;
	}


	public void setClassName(String className) {
		this.className = className;
	}


	public SectionService getSectionService() {
		return sectionService;
	}


	public void setSectionService(SectionService sectionService) {
		this.sectionService = sectionService;
	}
	
	public static void main(String[] args) {
		try{
    		JSONArray jsonDataArray = new JSONArray();
           	JSONObject parentNode = new JSONObject();
           	JSONObject parentNodeAttr = new JSONObject();
           	parentNodeAttr.put("id", "roles");
        	parentNodeAttr.put("name", "roles");
           	JSONObject parentNodeMetaData = new JSONObject();

        	//List<Role> roleLists = roleService.getRoles();
        	
           	/*List<String> roleLists = new ArrayList<String>();
           	roleLists.add("ROLE_ADMIN");
           	roleLists.add("ROLE_DEFAULT");*/

        	parentNode.put("data", "Roles");
        	parentNode.put("attr", parentNodeAttr);
        	//parentNode.put("children", parentNodeAttr);
        	
        	JSONArray childJsonDataArray = new JSONArray();

        	/*for(Role roleList : roleLists){
        		
        		JSONObject superChildNode = new JSONObject();
    			JSONObject superChildNodeAttr = new JSONObject();    			
    			superChildNodeAttr.put("id",roleList.getId());
    			superChildNodeAttr.put("name",roleList.getName());
    			superChildNodeAttr.put("parent",parentNode.get("data"));
    			
    			superChildNode.put("data", roleList.getName());
    			//superChildNode.put("attr", superChildNodeAttr);
    			superChildNode.put("metaData", superChildNodeAttr);

    			if(superChildNode != null){
    				childJsonDataArray.put(superChildNode);
    			}
        	}*/
        	parentNode.put("children", childJsonDataArray);
        	jsonDataArray.put(parentNode);
        	//return jsonDataArray;
    	}catch(Exception e){
    		//throw new BpmException("error"+e.getMessage(),e);
    	}
	}

}
